#include <stdio.h>
#include <algorithm>
using namespace std;

#define rep(i,n) for (int i=1; i<=n; i++)

#define TRACE(x...) x
#define PRINT(x...) TRACE(printf(x))

#define INF 0x3f3f3f3f

int p, m, b;
int pd[1010][110];
int best;
int tmp;
int t;

int main() {
	rep(i,100) pd[1][i]=1;
	rep(i,1000) pd[i][1]=i;
	rep(i,100) pd[0][i]=0;
	rep(i,1000) pd[i][0]=INF;

	for (int i=2; i<=1000; i++) {
		for (int j=2; j<=100; j++) {
			best=INF;	

			rep(k,i) {
				tmp=1+max(pd[k-1][j-1],pd[i-k][j]);
				//PRINT("com k: %d, tmp = %d\n", k, tmp);
				if (best>tmp) best=tmp;
			}

			pd[i][j]=best;
		}
	}

	scanf("%d", &p);
	while (p--) {
		scanf("%d %d %d", &t, &b, &m);
		printf("%d %d\n", t, pd[m][b]);
	}

	return 0;
}
